<?php

$revisions = $db->fetchCol("SELECT r.id FROM site_pages p LEFT JOIN site_pages_revisions r ON p.id=r.page_id WHERE site_id=? AND p.id=? AND r.id>p.revision_id", array($site['id'], $_REQUEST['id']));
$revisions = join(',', $revisions);

$db->query("DELETE FROM site_pages_revisions_content WHERE revision_id IN ({$revisions})");
$db->query("DELETE FROM site_pages_revisions_plugins WHERE revision_id IN ({$revisions})");
$db->query("DELETE FROM site_pages_revisions WHERE id IN ({$revisions})");

header('Content-type: application/json');
echo json_encode(array('id' => $_REQUEST['id']));